package me.zhengjie.modules.quartz.task.processing;

import com.qiaofang.applet.common.util.RedisKeyUtil;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.modules.sync.processing.*;
import me.zhengjie.utils.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/*
* 二手房解析TASK
* */
@Slf4j
@Component
public class PropertySequentialProcessingTask {

    @Autowired
    PropertySyncProcessing propertySyncProcessing;

    @Autowired
    DistrictSyncProcessing districtSyncProcessing;

    @Autowired
    AreaSyncProcessing areaSyncProcessing;

    @Autowired
    EstateSyncProcessing estateSyncProcessing;

    @Autowired
    EstatePhotoSyncProcessing estatePhotoSyncProcessing;

    @Autowired
    DepartmentSyncProcessing departmentSyncProcessing;

    @Autowired
    EmployeeSyncProcessing employeeSyncProcessing;

    @Autowired
    PropertyVrSyncProcessing propertyVrSyncProcessing;

    @Autowired
    PropertyVideoSyncProcessing propertyVideoSyncProcessing;

    @Autowired
    PropertyContactSyncProcessing propertyContactSyncProcessing;

    @Autowired
    PropertyRoleSyncProcessing propertyRoleSyncProcessing;

    @Autowired
    private RedisUtils redisUtils;


    public void processing(){
        String taskKey = RedisKeyUtil.getTaskKey(this.getClass().getSimpleName());
        if (redisUtils.hasKey(taskKey)){
            return;
        }
        redisUtils.set(taskKey, "", 30, TimeUnit.MINUTES);
        //部门
        try {
            log.info("departmentSyncProcessing run start");
            Long startTime = System.currentTimeMillis();
            departmentSyncProcessing.run();
            Long endTime = System.currentTimeMillis();
            log.info("departmentSyncProcessing run end {}", (endTime - startTime));
        } catch (Exception e) {
            log.error("departmentSyncProcessing error", e);
        }
        //经纪人
        try {
            log.info("employeeSyncProcessing run start");
            Long startTime = System.currentTimeMillis();
            employeeSyncProcessing.run();
            Long endTime = System.currentTimeMillis();
            log.info("employeeSyncProcessing run end {}", (endTime - startTime));
        } catch (Exception e) {
            log.error("employeeSyncProcessing error", e);
        }
        //区域
        try {
            log.info("districtSyncProcessing run start");
            Long startTime = System.currentTimeMillis();
            districtSyncProcessing.run();
            Long endTime = System.currentTimeMillis();
            log.info("districtSyncProcessing run end {}", (endTime - startTime));
        } catch (Exception e) {
            log.error("districtSyncProcessing error", e);
        }

        //商圈
        try {
            log.info("areaSyncProcessing run start");
            Long startTime = System.currentTimeMillis();
            areaSyncProcessing.run();
            Long endTime = System.currentTimeMillis();
            log.info("areaSyncProcessing run end {}", (endTime - startTime));
        } catch (Exception e) {
            log.error("areaSyncProcessing error", e);
        }
        //楼盘
        try {
            log.info("estateSyncProcessing run start");
            Long startTime = System.currentTimeMillis();
            estateSyncProcessing.run();
            Long endTime = System.currentTimeMillis();
            log.info("estateSyncProcessing run end {}", (endTime - startTime));
        } catch (Exception e) {
            log.error("estateSyncProcessing error", e);
        }

        //楼盘图片
        try {
            log.info("estatePhotoSyncProcessing run start");
            Long startTime = System.currentTimeMillis();
            estatePhotoSyncProcessing.run();
            Long endTime = System.currentTimeMillis();
            log.info("estatePhotoSyncProcessing run end {}", (endTime - startTime));
        } catch (Exception e) {
            log.error("estatePhotoSyncProcessing error", e);
        }

        try {
            log.info("propertyVrSyncProcessing run start");
            Long startTime = System.currentTimeMillis();
            propertyVrSyncProcessing.run();
            Long endTime = System.currentTimeMillis();
            log.info("propertyVrSyncProcessing run end {}", (endTime - startTime));
        } catch (Exception e) {
            log.error("propertyVrSyncProcessing error", e);
        }

        try {
            log.info("propertyVideoSyncProcessing run start");
            Long startTime = System.currentTimeMillis();
            propertyVideoSyncProcessing.run();
            Long endTime = System.currentTimeMillis();
            log.info("propertyVideoSyncProcessing run end {}", (endTime - startTime));
        } catch (Exception e) {
            log.error("propertyVideoSyncProcessing error", e);
        }

        try {
            log.info("propertyContactSyncProcessing run start");
            Long startTime = System.currentTimeMillis();
            propertyContactSyncProcessing.run();
            Long endTime = System.currentTimeMillis();
            log.info("propertyContactSyncProcessing run end {}", (endTime - startTime));
        } catch (Exception e) {
            log.error("propertyContactSyncProcessing error", e);
        }

        try {
            log.info("propertySyncProcessing run start");
            Long startTime = System.currentTimeMillis();
            propertySyncProcessing.run();
            Long endTime = System.currentTimeMillis();
            log.info("propertySyncProcessing run end {}", (endTime - startTime));
        } catch (Exception e) {
            log.error("firsthandEstateSyncProcessing error", e);
        }

        try {
            log.info("PropertyRoleSyncProcessing run start");
            Long startTime = System.currentTimeMillis();
            propertyRoleSyncProcessing.run();
            Long endTime = System.currentTimeMillis();
            log.info("propertySyncProcessing run end {}", (endTime - startTime));
        } catch (Exception e) {
            log.error("PropertyRoleSyncProcessing error", e);
        }
        redisUtils.del(taskKey);
    }

}
